//
//  UIBarButtonItem+Extensions.swift
//  Weibo
//
//  Created by apple on 2016/11/30.
//  Copyright © 2016年 yanjun. All rights reserved.
//

import UIKit

extension UIBarButtonItem {
    
    
    /// 创建 UIBarButtonItem
    ///
    /// - Parameters:
    ///   - title: title
    ///   - fontSize: fontSize 默认16
    ///   - target: target
    ///   - action: action
    convenience init(title:String,fontSize: CGFloat = 16,target: AnyObject?,action:Selector, isBack: Bool = false) {
        let btn: UIButton = UIButton.cz_textButton(title, fontSize: fontSize, normalColor: UIColor.darkGray, highlightedColor: UIColor.orange)
        
        if isBack {
            let imageName = "navigationbar_back_withtext"
            btn.setImage(UIImage.init(named: imageName), for: UIControlState.normal)
            btn.setImage(UIImage.init(named: imageName + "_highlighted"), for: UIControlState.highlighted)
        }
        
        btn.addTarget(target, action: action, for: UIControlEvents.touchUpInside)
        btn.sizeToFit()
        // self.init 实例化 UIBarButtonItem

        self.init(customView:btn)
    }
    
}


